package com.txsj.scan.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.txsj.scan.R;
import com.txsj.scan.bean.AllocationDetailsBean;
import com.txsj.scan.utils.glide.GlideImgManager;

import java.util.ArrayList;
import java.util.List;



/**
 * Created by 冯瑞雨 on 2018/12/11.
 * 库存调拨 调拨单 适配器
 */
public class AllocationSingleAdapeter extends RecyclerView.Adapter<AllocationSingleAdapeter.ItemView> {

    private Context context;
    private List<AllocationDetailsBean.DetailsBean> list = new ArrayList<>();



    public AllocationSingleAdapeter(Context context) {
        this.context = context;
    }

    public List<AllocationDetailsBean.DetailsBean> getList() {
        return list;
    }

    public void setList(List<AllocationDetailsBean.DetailsBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public ItemView onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.allocation_superingle_adapeter, parent, false);
        return new ItemView(inflate);
    }

    @Override
    public void onBindViewHolder(ItemView holder, final int position) {
        GlideImgManager.getLoadImg(context,list.get(position).getGoods_img(),holder.inventoryImage);
        holder.tvGoodsName.setText(list.get(position).getGoods_name());
        holder.tvAllocationNumber.setText("调拨数量："+list.get(position).getGoods_count());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                allocationSingleListener.onItemClickListener(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size() == 0 ? 0 : list.size();
    }

    public class ItemView extends RecyclerView.ViewHolder {
        ImageView inventoryImage;
        TextView tvGoodsName;
        TextView tvAllocationNumber;
        TextView surplusMoneyNumber;
        TextView surplusMoneyState;
        public ItemView(View itemView) {
            super(itemView);
             inventoryImage = (ImageView) itemView.findViewById(R.id.inventory_image);
             tvGoodsName = (TextView) itemView.findViewById(R.id.tv_goods_name);
             tvAllocationNumber = (TextView) itemView.findViewById(R.id.tv_allocation_number);
            surplusMoneyNumber = (TextView) itemView.findViewById(R.id.surplus_money_number);
            surplusMoneyState = (TextView) itemView.findViewById(R.id.surplus_money_state);

        }
    }
    public AllocationSingleListener allocationSingleListener;

    public void setAllocationSingleListener(AllocationSingleListener allocationSingleListener) {
        this.allocationSingleListener = allocationSingleListener;
    }

    public interface AllocationSingleListener{
        void onItemClickListener(int position);
    }
}
